﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/site.Master" Inherits="System.Web.Mvc.ViewPage<dynamic>" %>

<asp:Content ID="Content1" ContentPlaceHolderID="MainContent" runat="server">
<div class="w_980">
	<!--back_box-->
	<div class="back_box clearfix">
    	<!--left-->
    	<!--left-->
    	<% 
            Html.RenderPartial("~/Views/Shared/VipCenterList.ascx");
        %>
    	<!--right-->
        <div class="back_main">
        	<h3>阅读记录</h3>
            <div class="old_order_box">
                <!--table_box-->
                <div class="table_box">
                	<table>                                                                                
                    	<thead>
                        	<tr>
                            	<th width="230">书名</th>
                            	<th width="90">借阅时间</th>
                            	<th width="205" class="txt_left">家长评价</th>
                            	<th>操作</th>
                            </tr>
                        </thead>
                        <tbody>
                                                 <%
                        int pageno = Request["pageno"] == null ? 1 : int.Parse(Request["pageno"].ToString());//当前页
                        int pagesize = 15;//单页记录数
                        int count = 0;//总记录数
                        int pageNumber = 0;//总页数
                        int i = 1;//判断基数偶数
                        IList list = (IList)ViewData["list"];
                        foreach (Hashtable tb in list)
                        {
                            if (tb["total"] == null)
                            {
                                Response.Write("<tr " + ((i % 2) != 0 ? "class=\"tr_bg\"" : "") + ">");
                                Response.Write("<td><a href=\"/search/detail.html?id=" + tb["lb_id"] + "\" class=\"book_title_color\">" + tb["lb_bookName"] + "</a><em>作者：" + tb["lb_author"] + "</em><em>出版社：" + tb["lb_press"] + "</em></td>");
                                Response.Write("<td class=\"txt_center\">" + DateTime.Parse(tb["lbi_time"].ToString()).ToString("yyyy.MM.dd") + "</td>");
                                Response.Write("<td>" + tb["lbi_appraisal"] + "</td>");
                                Response.Write("<td><div class=\"con_btn_box\">");
                                if (tb["lbi_recommend"].ToString() == "0")
                                {
                                    Response.Write("<a href=\"#\" onclick=\"recommend(" + tb["lbid_id"] + ")\" class=\"a1\">推荐图书</a>");
                                }
                                else
                                {
                                    Response.Write("<a href=\"#\" class=\"a2\">已经推荐</a>");
                                }
                                if (string.IsNullOrEmpty(tb["lbi_appraisal"].ToString()))
                                {
                                    Response.Write("<a href=\"#\" onclick=\"appraisal(" + tb["lbid_id"] + ")\"  class=\"a4\">阅读评价</a>");
                                }
                                else
                                {
                                    Response.Write("<a href=\"#\" class=\"a3\">已经评价</a>");
                                }
                                Response.Write("</div></td>");
                                Response.Write("</tr>");
                                i++;
                            }
                            else
                                count = (tb["total"] == null ? 0 : int.Parse(tb["total"].ToString()));
                        }  
                        %>
                        </tbody>
                    </table>
                </div>
            	<!--bottom_bar-->
            	<div class="pager">
                <%
                    pageNumber = ((count % pagesize) == 0 ? (count / pagesize) : ((count / pagesize) + 1));
                    int start = pagesize * (pageno - 1) + 1;
                    if (start < 0)
                        start = 0;
                    int end = (start + pagesize-1);
                    if (pageno == pageNumber)
                    {
                        if ((count % pagesize) != 0)
                        {
                            end = (start + (count % pagesize) - 1);
                        }
                    }
                %>
                <p class="left"><%=count%> 条记录，显示第 <%=start %> 条 - 第 <%=end %> 条记录</p>
                <p class="right"><a href="/Vipcenter/readHistory.html?pageno=1" title="首页" class="a1 a1_n"></a>
                <a href="/Vipcenter/readHistory.html?pageno=<%=(pageno==1?1:pageno-1) %>" title="上一页" class="a2"></a><span>第<b><%=pageno %></b>页/共 <%=pageNumber %> 页</span>
                <a href="/Vipcenter/readHistory.html?pageno=<%=(pageno==pageNumber?pageNumber:pageno+1) %>" title="下一页" class="a3"></a><a href="/Vipcenter/readHistory.html.html?pageno=<%=pageNumber %>" title="末页" class="a4"></a>
                <select id="sPage">
                <% 
                    for (int k = 1; k <= pageNumber;k++ )
                        Response.Write("<option value=\"" + k.ToString() + "\">" + k.ToString() + "</option>");
                %>
                </select></p>
                <script type="text/javascript" language="javascript">
                    $(function () {
                        $("#sPage").val(<%=pageno %>);
                        $("#sPage").change(function () {
                            window.location.href = "/Vipcenter/readHistory.html.html?pageno=" + $("#sPage").val();
                        });
                    })
                </script>
            </div>
            </div>
        </div>
    </div>
</div>
<div id="dialog" title="阅读评价">
<textarea rows="6" style="width:98%" id="txtappraisal" name="txtappraisal"></textarea>
<span id="msg" style="color:Red"></span>
<input type="hidden" id="hid" name="hid" />
</div>
<script type="text/javascript">
    function recommend(id) {
        if (confirm("确认推荐？")) {
            $.post("/Vipcenter/recommend.html", { id: id }, function (dta) {
                alert("推荐成功");
                window.location.reload();
            });
        }
    }

    $(function () {
        // Dialog			
        $('#dialog').dialog({
            autoOpen: false,
            //modal: true,//如果要加遮罩层
            width: 400,
            buttons: {
                "确认": function () {
                    //$(this).dialog("close");
                    var id = $("#hid").val();
                    var appraisal = $("#txtappraisal").val();
                    if (appraisal == "") {
                        $("#msg").text("请填写评价内容");
                        $("#txtappraisal").focus();
                        return false;
                    }
                    $.post("/Vipcenter/appraisal.html", { id: id, appraisal: appraisal }, function (dta) {
                        alert("评价成功");
                        window.location.reload();
                    })
                },
//                "取消": function () {
//                    $(this).dialog("close");
//                }
            }
        });
    });
    // Dialog Link
    function appraisal(id) {
        $("#hid").val(id);
        $('#dialog').dialog('open');
        return false;
    }
</script>
</asp:Content>
